package cn.student.controller;

import cn.student.config.web.ResponseMessage;
import cn.student.config.web.ResponseStatusCode;
import cn.student.pojo.Register;
import cn.student.pojo.vo.JwtUser;
import cn.student.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 毛苏宇
 * User: me
 * Date: 2020/6/26
 * Time: 11:31
 * Description:
 */
@RestController
public class RegisterController {

    @Autowired
    private RegisterService registerService;

    /**
     * 报名参赛
     *
     * @return
     */
    @PostMapping("/register")
    public ResponseMessage register(JwtUser user, Register register) {
        register.setUserId(user.getJwtId());
        boolean add = registerService.add(register);
        if (add) {
            return new ResponseMessage(ResponseStatusCode.CODE_SUCCESS, "报名成功", null);
        }
        return new ResponseMessage(ResponseStatusCode.CODE_FAIL, "报名失败", null);
    }

}
